package com.zito.health.service.impl;

import com.zito.health.common.service.impl.BaseServiceImpl;
import com.zito.health.entity.ItemExpertConclusion;
import com.zito.health.mapper.ItemExpertConclusionMapper;
import com.zito.health.service.ItemExpertConclusionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2019/11/11.
 */
@Service
public class ItemExpertConclusionServiceImpl extends BaseServiceImpl<ItemExpertConclusion> implements ItemExpertConclusionService {

    @Autowired
    private ItemExpertConclusionMapper itemExpertConclusionMapper;

    @Override
    public int queryMinExpert() {
        return itemExpertConclusionMapper.queryMinExpert();
    }

    public int save(Integer itemId, String[] ids) {
        int res = 0;
        for(String id : ids) {
            ItemExpertConclusion itemExpertConclusion = new ItemExpertConclusion();
            itemExpertConclusion.setItemId(itemId);
            itemExpertConclusion.setExpertId(Integer.valueOf(id));
            itemExpertConclusion.setStates(1);
            itemExpertConclusion.setOpinion(" ");
            itemExpertConclusion.setResult(0);
            res = res + itemExpertConclusionMapper.insertSelective(itemExpertConclusion);
        }
        return res;
    }

    @Override
    public void saveConclusion(ItemExpertConclusion item) {

        ItemExpertConclusion select = itemExpertConclusionMapper.selectByPrimaryKey(item.getId());
        if(select!=null){
            itemExpertConclusionMapper.updateByPrimaryKeySelective(item);
        }else {
            itemExpertConclusionMapper.insertSelective(item);
        }

    }

}
